package main

import (
	"crowl_qqp/fetcher"
	"fmt"
	"crowl_qqp/models"
	"strconv"
	"os"
	"bufio"
)

var mvContent = make(chan string)
var mvUrl= make(chan string)

func main() {

	var list = make([]string,0)
	var  i =0
	for{
		url:=`http://www.qiqipu.com/mdown/?mid=33447&m_addr=0&mpart=`+strconv.Itoa(i)
		content, err := fetcher.Fetch(url)
		if err !=nil {
			fmt.Println(err)
		}
		xunlei:=models.GetXunLeiUrl(string(content))
		if xunlei!="" {
			list=append(list,xunlei)
			i++
		}else {
			fmt.Println("url nil")
			break
		}
	}
	WriteMaptoFile(list,"E:\\qqp.txt")


}

func WriteMaptoFile(m []string, filePath string) error {
	f, err := os.Create(filePath)
	if err != nil {
		fmt.Printf("create map file error: %v\n", err)
		return err
	}
	defer f.Close()

	w := bufio.NewWriter(f)
	for _, v := range m {
		fmt.Fprintln(w, v)
	}
	return w.Flush()
}


